﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.z00_zjlxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void z00_zjlx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            z00_zjlxMgr mgr = new z00_zjlxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_z00_zjlx(e.Parameters[z00_zjlx_Filter.ParamPrefix]));
            IList<z00_zjlx> list = mgr.FindAllByPage_z00_zjlx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[z00_zjlx_Filter.ParamPrefix]);
            z00_zjlx_MainStore.DataSource = list;
            z00_zjlx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            z00_zjlxMgr mgr = new z00_zjlxMgr();
            RowSelectionModel sm = z00_zjlx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                z00_zjlx _z00_zjlx = new z00_zjlx();
                _z00_zjlx.bh = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_z00_zjlx(_z00_zjlx))
                {
                    log.Debug("z00_zjlx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            z00_zjlx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            z00_zjlxMgr mgr = new z00_zjlxMgr();
            z00_zjlx _z00_zjlx = new z00_zjlx();
            if (Hid.Text.Length > 0)
                _z00_zjlx = mgr.FindById_z00_zjlx(int.Parse(Hid.Text));
            
			_z00_zjlx.nf = Txtnf.Text.Trim();
			_z00_zjlx.zjmc = Txtzjmc.Text.Trim();
			_z00_zjlx.zjbl = Txtzjbl.Text.Trim();
			_z00_zjlx.sta = Txtsta.Text.Trim();
			_z00_zjlx.end1 = Txtend1.Text.Trim();
			_z00_zjlx.yxbz = int.Parse(TxtNumyxbz.Text.Trim());
			_z00_zjlx.dqbm = Txtdqbm.Text.Trim();
			_z00_zjlx.pybm = Txtpybm.Text.Trim();
			_z00_zjlx.wbbm = Txtwbbm.Text.Trim();
			_z00_zjlx.qtbm = Txtqtbm.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_z00_zjlx(_z00_zjlx);
            else
                isok = mgr.Add_z00_zjlx(_z00_zjlx);
            if (isok)
            {
                z00_zjlx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("z00_zjlx中执行了保存（插入或修改），并成功");
                z00_zjlx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}